package com.springapi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springapi.entity.Maillist;
import com.springapi.dao.MaillistDao;
import com.springapi.entity.Users;
import com.springapi.service.MaillistService;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 快递列表(Maillist)表服务实现类
 *
 * @author makejava
 * @since 2025-01-13 20:37:16
 */
@Service("maillistService")
public class MaillistServiceImpl implements MaillistService {
    @Resource
    private MaillistDao maillistDao;




    @Override
    public List<Maillist> findlistbysendmsg(int appid, int shopid) {
        return maillistDao.findlistbysendmsg(appid,shopid);
    }

    @Override
    public Integer getnewpkcode(int appid, int shopid, String shelfnumber) {
        return maillistDao.getnewpkcode(appid,shopid,shelfnumber);
    }

    @Override
    public Integer findbynoout(int appid, int shopid) {
        return maillistDao.findbynoout(appid,shopid);
    }

    @Override
    public Integer findbyin(int appid, int shopid) {
        return maillistDao.findbyin(appid,shopid);
    }

    @Override
    public Integer findbyintime(int appid, int shopid, Date intime1, Date intime2) {

        return maillistDao.findbyintime(appid,shopid,intime1,intime2);
    }

    @Override
    public Integer findbyouttime(int appid, int shopid, Date outtime1, Date outtime2) {

        return maillistDao.findbyouttime(appid,shopid,outtime1,outtime2);
    }

    @Override
    public Integer findbyabnormal(int appid, int shopid, Integer days) {

        return maillistDao.findbyabnormal(appid,shopid,days);
    }

    @Override
    public List<Maillist> findlistbyabnormal(int appid, int shopid, Integer days) {
        return maillistDao.findlistbyabnormal(appid,shopid,days);
    }


    @Override
    public List<Maillist> findbywaybill(int appid,int shopid,String waybill) {
        //return maillistDao.findbywaybill(waybill);

        List<Maillist> result = maillistDao.findbywaybill(appid,shopid,waybill);
        return result.isEmpty() ? null : result;
    }

    @Override
    public PageInfo<Maillist> myfindAll(int appid, int shopid, int page, int size, String isout, String waybill, String pkcodestr, String name, String mobile) {

        // 这句代码要放在查询 mapper 语句的前面
        PageHelper.startPage(page, size);
        Pageable pageable = PageRequest.of(page, size);
        //myfindAll第三个参数代表角色，2为员工3为客户
        List<Maillist> Maillists = maillistDao.myfindAll(appid,shopid,isout,waybill,pkcodestr,name,mobile);
        PageInfo<Maillist> pageInfo = new PageInfo<>(Maillists);
        return  pageInfo;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Maillist queryById(Integer id) {
        return this.maillistDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param maillist 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Maillist> queryByPage(Maillist maillist, PageRequest pageRequest) {
        long total = this.maillistDao.count(maillist);
        return new PageImpl<>(this.maillistDao.queryAllByLimit(maillist, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param maillist 实例对象
     * @return 实例对象
     */
    @Override
    public Maillist insert(Maillist maillist) {
        this.maillistDao.insert(maillist);
        return maillist;
    }

    /**
     * 修改数据
     *
     * @param maillist 实例对象
     * @return 实例对象
     */
    @Override
    public Maillist update(Maillist maillist) {
        this.maillistDao.update(maillist);
        return this.queryById(maillist.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.maillistDao.deleteById(id) > 0;
    }
}
